package com.boco.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.boco.entity.EMR_XYCFYYMX;

public class GetEMR_XYCFYYMXData {
	
	private static final Log log = LogFactory.getLog(GetEMR_XYCFYYMXData.class);
	public static List<EMR_XYCFYYMX> getData()
	{
	    Connection con = null;
	    PreparedStatement pre = null;
	    ResultSet result = null;
	    List<EMR_XYCFYYMX> re = new ArrayList<EMR_XYCFYYMX>();
	    try
	    {
	        Class.forName("oracle.jdbc.driver.OracleDriver");
	        System.out.println("开始尝试连接数据库！");
	        String url = "jdbc:oracle:" + "thin:@172.20.21.12:1521:orcl";
	        String user = "sjzx_hxk";
	        String password = "boco#1234";
	        con = DriverManager.getConnection(url, user, password);
	        System.out.println("连接成功！");
	        String sql = "select "
	        		+"'' as HZZSYH, "
	        		+"a.yljgdm as YLJGZZJGDM, "
	        		+"a.jzlsh as MJZH, "
	        		+"a.cfmxid as CFBH, "
	        		+"a.cfh as CFMXLSH, "
	        		+"to_char(b.kfrq,'yyyy-MM-dd HH24:mi:ss') as KCFRQ, "
	        		+"a.xmmc as YWMC, "
	        		+"a.xmbm as YPID, "
	        		+"a.ypgg as YWGG, "
	        		+"a.jxdm as YWJXDM, "
	        		+"a.sycjl as YWSYCJL, "
	        		+"a.sjyldw as YWSYJLDW, "
	        		+"a.sypc as YWSYPL, "
	        		+"a.yf as YWSYTJDM, "
	        		+"a.syzl as YWSYZJL, "
	        		+"'' as SFKSS, "
	        		+"'' as SFGJJY, "
	        		+"'' as SFJMYP, "
	        		+"'' as YPFY, "
	        		+"'' as ZRLSH, "

					+"to_char(a.ywscsj,'yyyy-MM-dd HH24:mi:ss') as BCRQ,"
					+"'' as ORGCODE,"
					+"'' as AREACODE,"
					+"to_char(sysdate,'yyyyMMddHH24miss') as UPLOADTIME,"
					+"'' as  SOURCEID "
					+" from tb_mz_cfmx a left join tb_mz_cfzb"
					+" 	 b on a.yljgdm = b.yljgdm and "
					+" 	 a.kh = b.kh and "
		        	+" 	 a.klx = b.klx ";
	 
	        log.info("查询sql："+sql);
	        pre = con.prepareStatement(sql);
	        result = pre.executeQuery();
	        System.out.println("执行成功");
	        while (result.next()){
	            //System.out.println(result.getString("CFMXLSH"));
	        	EMR_XYCFYYMX temp = new EMR_XYCFYYMX();
	        	temp.setHZZSYH(result.getString("HZZSYH"));
	        	temp.setYLJGZZJGDM(result.getString("YLJGZZJGDM"));
	        	temp.setMJZH(result.getString("MJZH"));
	        	temp.setCFBH(result.getString("CFBH"));
	        	temp.setCFMXLSH(result.getString("CFMXLSH"));
	        	temp.setKCFRQ(result.getString("KCFRQ"));
	        	temp.setYWMC(result.getString("YWMC"));
	        	temp.setYPID(result.getString("YPID"));
	        	temp.setYWGG(result.getString("YWGG"));
	        	temp.setYWJXDM(result.getString("YWJXDM"));
	        	temp.setYWSYCJL(result.getString("YWSYCJL"));
	        	temp.setYWSYJLDW(result.getString("YWSYJLDW"));
	        	temp.setYWSYPL(result.getString("YWSYPL"));
	        	temp.setYWSYTJDM(result.getString("YWSYTJDM"));
	        	temp.setYWSYZJL(result.getString("YWSYZJL"));
	        	temp.setSFKSS(result.getString("SFKSS"));
	        	temp.setSFGJJY(result.getString("SFGJJY"));
	        	temp.setSFJMYP(result.getString("SFJMYP"));
	        	temp.setYPFY(result.getString("YPFY"));

	        	temp.setZRLSH(result.getString("ZRLSH"));
	        	temp.setBCRQ(result.getString("BCRQ"));
	        	temp.setORGCODE(result.getString("ORGCODE"));
	        	temp.setAREACODE(result.getString("AREACODE"));
	        	temp.setUPLOADTIME(result.getString("UPLOADTIME"));
	        	temp.setSOURCEID(result.getString("SOURCEID"));
	        	re.add(temp);
	        }
	    }
	    catch (Exception e)
	    {
	        e.printStackTrace();
	    }
	    finally
	    {
	        try
	        {
	            if (result != null)
	                result.close();
	            if (pre != null)
	                pre.close();
	            if (con != null)
	                con.close();
	            System.out.println("数据库连接已关闭！");
	        }
	        catch (Exception e)
	        {
	            e.printStackTrace();
	        }
	    }
		return re;
	}
}
